if SERVER then
	registerCommand("slap", "Slaps the player you specify, you may optional specify the damage and number of times", function(param)
		local slapMsg = "caller slapped target for damage health iterations times"
		if param["settings"]["slap_msg"] then
			slapMsg = param["settings"]["slap_msg"]
		end
		local slapTable = {}
		slapTable["caller"] = getCaller(param[1])
		local targs = string.Explode(" ", param[3])
		
		//Separate out damage and iterations
		local damage = 10
		local iterations = 1
		if table.Count(targs) >= 3 && (not getPlayerByName(targs[table.Count(targs) - 1])) then
			damage = tonumber(targs[table.Count(targs) - 1])
			if not damage then
				return nil
			end
			table.remove(targs, table.Count(targs) - 1)
			if not getPlayerByName(targs[table.Count(targs)]) then
				iterations = tonumber(targs[table.Count(targs)])
				if not iterations then
					return nil
				end
				table.remove(targs, table.Count(targs))
			end
		else
			if not getPlayerByName(targs[table.Count(targs)]) then
				damage = tonumber(targs[table.Count(targs)])
				if not damage then
					return nil
				end
				table.remove(targs, table.Count(targs))
			end
		end
		if damage < 0 then
			damage = 0
		end
		if iterations < 1 then
			iterations = 1
		end
		for i, targ in pairs(targs) do
			local plyTarg = getPlayerByName(targ)
			if plyTarg then
				slapTable["target"] = plyTarg:GetName()
				slapTable["damage"] = damage
				slapTable["iterations"] = iterations
				display(param[1], "slap", { plyTarg } , parseDisplayMessage(slapMsg, slapTable))
				moocow_doslap(param[1], plyTarg, damage)
				if iterations - 1 > 0 then
					timer.Create("slap_" .. plyTarg:GetName(), 1.5, iterations - 1, moocow_doslap, param[1], plyTarg, damage)
				end
			end
		end
	end)
	
	function moocow_doslap(caller, target, damage)
		if target then
			if caller then
				local vect = Vector(1, 1, 1)
				if caller:IsValid() then
					vect = caller:GetAimVector()
				end
				vect.z = 1.5
				target:SetVelocity(vect * 500)
			else
				target:SetVelocity(Vector(250, 500, 1000))
			end
			target:ViewPunch(Angle(-50, 0, 0))
			target:SetHealth(target:Health() - damage)
			if target:Health() <= 0 then
				target:Kill()
				target:Spawn()
			end
			target:EmitSound("Flesh.ImpactHard")
			target:SetMoveType(MOVETYPE_WALK)
		end
	end
	
	function moocow_cancelSlap(ply)
		if timer.IsTimer("slap_" .. ply:GetName()) then
			timer.Destroy("slap_" .. ply:GetName())
		end
	end
	hook.Add("PlayerDisconnected", "moowcow_cancelslap", moocow_cancelSlap)
end